import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:music_player/model/theme_model.dart';
import 'package:music_player/page/MusicPage.dart';
import 'package:music_player/providers/provider_setup.dart';
import 'package:music_player/utils/init_util.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'application.dart';


void main() {
  // 简单处理原生跟flutter通信
  WidgetsFlutterBinding.ensureInitialized();

  runApp(MultiProvider(
      providers: provides,
      child: const MyApp()
  ));
  appWindow.show();
  doWhenWindowReady(() {
    final win = appWindow;
    const initialSize = Size(800, 500); //初始化
    win.minSize = initialSize; // 设置软件最小窗口大小
    win.size = initialSize; // 默认的窗口大小
    win.alignment = Alignment.center; // 窗口的位置
    win.title = "Flutter Music"; // 窗口标题
    win.show(); // 展示
  });
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    //final themeModel = context.watch<ThemeModel>();
    return MaterialApp(
      navigatorKey: navigatorKey,
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.pink),
        useMaterial3: true,
      ),
      home: Scaffold(
        //backgroundColor: Colors.transparent,
        body: Container(
          child: MoveWindow(
            child: Stack(
              children: [
                Application(child: MusicPage()),
                Positioned(
                  top: 10,
                  right: 5,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      MouseRegion(
                        cursor: SystemMouseCursors.click,
                        child: MinimizeWindowButton(),
                      ),
                      // MaximizeWindowButton(),
                      CloseButton(),
                      const SizedBox(
                        width: 30,
                      )
                    ],
                  ),
                ),
                Positioned(
                  top: 5,
                  left: 5,
                  child: GestureDetector(
                      onTap: () {
                        initMusicList(context);
                      },
                      child: Icon(Icons.arrow_drop_down,
                          color: context.watch<ThemeModel>().themeColor)),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class CloseButton extends CloseWindowButton{
  CloseButton({super.key}):super(onPressed: (){
    appWindow.hide();
  });

}